<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>@ViewData["Title"] - MyERP</title>
		<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
		<link href="~/layui/css/layui.css" rel="stylesheet">
		<script src="~/lib/jquery/dist/jquery.min.js"></script>
		<script src="~/js/site.js" asp-append-version="true"></script>
		<script src="~/layui/layui.js"></script>
		<script src="~/js/echarts.min.js"></script>
	</head>
	<body class="layui-bg-gray">
		<header>
			<ul class="layui-nav" lay-filter="demo-filter-nav" id="daoHangId">

			</ul>
		</header>
		<div class="">
			<main>
				@RenderBody()
			</main>
		</div>




		<script>
			//获取当前登陆用户信息
			const user = JSON.parse(localStorage.getItem('user'));
			//获取当前导航条
			let daoHang = document.getElementById('daoHangId');
			//通过登陆用户权限配置导航菜单
			if (user.q1 == 1) {
				//在元素最后插入html
				daoHang.insertAdjacentHTML('beforeend', `<li class="layui-nav-item " id="n1">
					<a href="/" >首页</a>
				</li>`);
			}
			if (user.q2 == 1) {
				daoHang.insertAdjacentHTML('beforeend', `<li class="layui-nav-item" id="n2">
					<a href="javascript:;">采购管理</a>
					<dl class="layui-nav-child">
						<dd><a href="/Purchase">添加采购单</a></dd>
						<dd><a href="/Purchase/Query">采购查询</a></dd>
					</dl>
				</li>`);
			}
			if (user.q3 == 1) {
				daoHang.insertAdjacentHTML('beforeend', `<li class="layui-nav-item" id="n3">
					<a href="javascript:;">销售管理</a>
					<dl class="layui-nav-child">
						<dd><a href="/Sale">添加销售单</a></dd>
						<dd><a href="/Sale/Query">销售查询</a></dd>
					</dl>
				</li>`);
			}
			if (user.q4 == 1) {
				daoHang.insertAdjacentHTML('beforeend', `<li class="layui-nav-item" id="n4">
					<a href="/Finance">收支管理</a>
				</li>`);
			}
			if (user.q1 == 1 && user.q2 == 1 && user.q3 == 1 && user.q4 == 1) {
				daoHang.insertAdjacentHTML('beforeend', `<li class="layui-nav-item" id="n5">
					<a href="javascript:;">设置</a>
					<dl class="layui-nav-child">
						<dd><a href="/Users">用户管理</a></dd>
					</dl>
				</li>`);
			}
			//设置当前登陆用户
			daoHang.insertAdjacentHTML('beforeend', `<li class="layui-nav-item" id="">
					<a href="javascript:;" onclick="alertUser()">${user.name}</a>
				</li>`);
			//显示用户信息
			function alertUser() {
				layui.use(function() {
					var layer = layui.layer;
					layer.open({
						type: 1,
						area: ['420px', '240px'], // 宽高
						title: '用户权限',
						content: `<div style="padding: 11px;"><p>当前用户：${user.name}</p>
									<p>首页权限：${user.q1}</p>
									<p>采购权限：${user.q2}</p>
									<p>销售权限：${user.q3}</p>
									<p>收支权限：${user.q4}</p>
									<button type="button" class="layui-btn layui-bg-red" onclick="location.href='/Login/Logout'">退出登陆</button></div>`
					});
				});
			}

			// 页面加载时执行
			window.onload = function() {
				// 获取当前路由
				const currentRoute = window.location.pathname;

				// 根据路由向特定元素添加 class
				switch (currentRoute) {
					case '/':
						document.getElementById('n1').classList.add('layui-this');
						break;
					case '/Purchase':
						document.getElementById('n2').classList.add('layui-this');
						break;
					case '/Purchase/Query':
						document.getElementById('n2').classList.add('layui-this');
						break;
					case '/Sale':
						document.getElementById('n3').classList.add('layui-this');
						break;
					case '/Sale/Query':
						document.getElementById('n3').classList.add('layui-this');
						break;
					case '/Finance':
						document.getElementById('n4').classList.add('layui-this');
						break;
					case '/Users':
						document.getElementById('n5').classList.add('layui-this');
						break;
					default:
						break;
				}

			};
		</script>

		@await RenderSectionAsync("Scripts", required: false)
	</body>
</html>